package com.kitty.game.haoxinzhi.service;

import com.kitty.common.utils.SpringUtils;
import com.kitty.game.config.NPC;
import com.kitty.game.haoxinzhi.message.RespHaoXinZhiShop;
import com.kitty.game.haoxinzhi.model.HaoXinZhiReward;
import com.kitty.game.haoxinzhi.model.HaoXinZhiShop;
import com.kitty.game.role.model.Role;
import com.kitty.mina.cache.DataCache;
import com.kitty.mina.message.MessagePusher;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

@Service
public class NiceService {
   @Autowired
   private Dao dao;

   public void nicefoNpc(Role role, String msg, NPC npc) {
      if ("open_GoodValue".equals(msg)) {
         SpringUtils.getRoleService().Sendupdatehaoxianzhijifen(role);
         RespHaoXinZhiShop shop = new RespHaoXinZhiShop();
         List<HaoXinZhiShop> list = new ArrayList();
         List<HaoXinZhiReward> fetchList = this.dao.query(HaoXinZhiReward.class, Cnd.NEW());
         Iterator var7 = fetchList.iterator();

         while(var7.hasNext()) {
            HaoXinZhiReward haoXinZhiReward = (HaoXinZhiReward)var7.next();
            HaoXinZhiShop haoXinZhiShop = new HaoXinZhiShop();
            haoXinZhiShop.setWupinname(haoXinZhiReward.getName());
            haoXinZhiShop.setPrice(haoXinZhiReward.getPrice());
            DataCache.HAOXINZHI_GOODS.put(haoXinZhiReward.getName(), haoXinZhiReward);
            list.add(haoXinZhiShop);
         }

         shop.setType((byte)2);
         shop.setList(list);
         MessagePusher.pushMessage((Role)role, shop);
      }

   }
}
